package com.yuebao.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.yuebao.utils.RedisConstants.FUND_MQ_CONSUMER;

@Service
public class RedissonService {
    
    @Resource
    RedissonClient redissonClient;
    
    
    //消费加锁
    public Boolean messageTryLock(String messageId){
        RLock lock = redissonClient.getLock(FUND_MQ_CONSUMER+messageId);
        return lock.tryLock();
    }
    public void messageIdUnLock(String messageId){
        RLock lock = redissonClient.getLock(FUND_MQ_CONSUMER+messageId);
        lock.unlock();
    }
    
    public boolean isMessageExist(String messageId){
        RLock lock = redissonClient.getLock(FUND_MQ_CONSUMER+messageId);
        return lock.isLocked();
    }
}
